package ${pk.controllerPackage};
<#if (pk.controllerSuperClassPackage)??>

import ${pk.controllerSuperClassPackage}.${pk.controllerSuperClassNme};
</#if>
import ${pk.entityPackage}.${pk.entityName};
import ${pk.helpPackage}.${pk.helpName};
import ${pk.paramPackage}.${pk.paramName};
import ${pk.servicePackage}.${pk.serviceName};
import ${pk.queryForOneRowParamPackage}.${pk.queryForOneRowParamName};
import ${pk.queryPageParamPackage}.${pk.queryPageParamName};
import ${pk.voPackage}.${pk.voName};
import common.core.util.CommonUtil;
import common.core.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import enhance.plus.logic.LogicBaseController;
import enhance.plus.util.Page;
import enhance.plus.util.PageHelper;


import javax.validation.Valid;
import javax.validation.constraints.NotBlank;


<#assign nowDate = .now>
/**
 * ${table.comments!} 控制器
 *
 * @author ${author!'作者走丢了'}
 * @created ${nowDate?string("yyyy-MM-dd HH:mm:ss")}
 */
@Slf4j
@Validated
@RestController
@Api(tags = "${table.comments!}")
@RequestMapping("/${model}/${table.entityName?uncap_first}")
public class ${pk.controllerName}<#if (pk.controllerSuperClassNme)??> extends ${pk.controllerSuperClassNme}<${pk.serviceName}, ${pk.entityName}></#if> {

    @Autowired
    private ${pk.serviceName} ${pk.serviceName?uncap_first};

    @ApiOperation(value = "保存${table.comments!}的数据")
    @RequestMapping(value = "/save" , method = RequestMethod.PUT)
    public Result save(@Valid ${pk.paramName} param){
        //@TODO 请及时去修改 参数和返回值 的swagger 注解
        log.debug("开始保存${table.comments!}-->{}",param);
        return Result.success(this.${pk.serviceName?uncap_first}.save(CommonUtil.copyBean(param,${pk.entityName}.class)));
    }

    @ApiOperation(value = "更新${table.comments!}的数据")
    @RequestMapping(value = "/update" , method = RequestMethod.PUT)
    public Result update(@Valid ${pk.paramName} param){
        //@TODO 请及时去修改 参数和返回值 的swagger 注解
        log.debug("开始跟新${table.comments!}-->{}",param);
        return Result.success(this.${pk.serviceName?uncap_first}.updateById(CommonUtil.copyBean(param,${pk.entityName}.class)));
    }

    @ApiOperation(value = "删除${table.comments!}的一条数据")
    @RequestMapping(value = "/delete" , method = RequestMethod.DELETE)
    @ApiImplicitParams(
        @ApiImplicitParam(name= "id" ,value = "数据ID", required = true , example = "-1" )
    )
    public Result delete(@Valid @RequestParam @NotBlank(message = "删除数据ID不能为空") String id){
        log.debug("开始删除${table.comments!}的数据-->{}",id);
        return Result.success(this.${pk.serviceName?uncap_first}.removeById(id));
    }

    @ApiOperation(value = "根据条件查询一条${table.comments!}的数据")
    @RequestMapping(value = "/queryForOneRow" , method = RequestMethod.POST)
    public Result<${pk.voName}> queryForOneRow(@Valid ${pk.queryForOneRowParamName} param){
        //@TODO 请及时去修改 参数和返回值 的swagger 注解
        ${pk.entityName} row = this.${pk.serviceName?uncap_first}.getOne(param.convertParamToQueryWapper());
        return Result.success( CommonUtil.copyBean(row, ${pk.voName}.class));
    }

    @ApiOperation(value = "根据条件分页查询${table.comments!}的数据")
    @RequestMapping(value = "/queryPage" , method = RequestMethod.POST)
    public Result<Page<${pk.voName}>> queryPage(@Valid ${pk.queryPageParamName} param , PageHelper helper){
        //@TODO 请及时去修改 参数和返回值 的swagger 注解
        return Result.success(this.${pk.serviceName?uncap_first}.page(helper.page(),param.convertParamToQueryWapper()));
    }

}
